<?php

class spGoogleDataTable
{
	private $headers;
	private $rows = array();
	
	public function __construct( $headers )
	{
		$this->headers = $headers;
	}
	
	public function addRow( $row )
	{
		$this->rows[] = $row;
	}
	
	public function render()
	{
		$cols = "";
		
		$cols.= '{ "label":"SELECT", "type":"string" },';
		foreach ( $this->headers as $h )
		{
			$cols.= '{ "label":"'.$h.'", "type":"string" },';
		}
		
		$cols = substr($cols,0,-1);

		$rows = "";
		foreach ( $this->rows as $r )
		{
			$elements = "";
			
			$elements.= '{"v":"test"},';
			
			foreach ( $r as $e )
			{
				$elements.= '{"v":"'.$e.'"},';
			}
			$elements = substr($elements,0,-1);
		
			$rows.= '{ "c":[ '.$elements.' ]},';
		}

		$rows = substr($rows,0,-1);
		
		echo '<div class="testtable">
		{
			"cols" : ['.$cols.'],
			"rows" : ['.$rows.']
		}
		</div>';	
	}
}

?>